//
//  LoginByCodeView.m
//  HaiGeEr_Student
//
//  Created by liuchen on 2018/9/9.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "LoginByCodeView.h"
@interface LoginByCodeView()
@property (nonatomic,weak) UILabel *title;
@property (nonatomic,weak) UIButton *selectBtn;
@property (nonatomic,weak) UILabel *readLabel;
@end
@implementation LoginByCodeView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark ==========创建视图==========
- (void)createSubView{
    self.selectJudge = YES; 
    //视图
    UILabel *title = [[UILabel alloc]init];
    title.text = @"验证码登录";
    title.textAlignment = NSTextAlignmentCenter;
    title.font = [UIFont fontWithName:@"Arial-BoldMT" size:LoginFont+9];
    title.textColor = RGBA(50, 50, 50, 1);
    _title = title;
    [self addSubview:self.title];
    LoginInPutView *phoneView = [[LoginInPutView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) WithImageName:@"7-1-2" WithTitle:@"请输入手机号码" WithLocation:0];
    phoneView.textField.keyboardType = UIKeyboardTypeNumberPad;
    _phoneView = phoneView;
    [self addSubview:self.phoneView];
    LoginInPutView *codeView = [[LoginInPutView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) WithImageName:@"7-1-3" WithTitle:@"请输入验证码" WithLocation:2];
    codeView.textField.keyboardType = UIKeyboardTypeNumberPad;
    _codeView = codeView;
    [self addSubview:self.codeView];
    UIButton *codeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [codeBtn setBackgroundColor:LOGINBACKRGBA];
    [codeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
    [codeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    [codeBtn.titleLabel setFont:[UIFont systemFontOfSize:LoginFont-4]];
    [codeBtn setTitleColor:RGBA(50, 50, 50, 1) forState:UIControlStateNormal];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 150*SCALEUNIT, 40*SCALEUNIT) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(5*SCALEUNIT,5*SCALEUNIT)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = CGRectMake(0, 0, 150*SCALEUNIT, 40*SCALEUNIT);
    maskLayer.path = maskPath.CGPath;
    codeBtn.layer.mask = maskLayer;
    _codeBtn = codeBtn;
    [self addSubview:self.codeBtn];
    UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [selectBtn setImage:[UIImage imageNamed:@"7-1-6"] forState:UIControlStateNormal];
    [selectBtn setImage:[UIImage imageNamed:@"7-1-5"] forState:UIControlStateSelected];
    [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(15*SCALEUNIT, 5*SCALEUNIT, 15*SCALEUNIT, 5*SCALEUNIT)];
    [selectBtn addTarget:self action:@selector(selectChange:) forControlEvents:UIControlEventTouchUpInside];
    _selectBtn = selectBtn;
    [self addSubview:self.selectBtn];
    NSInteger fontSize = LoginFont-5;
    UILabel *readLabel = [[UILabel alloc]init];
    readLabel.text = @"已阅读并同意";
    readLabel.font = [UIFont systemFontOfSize:fontSize];
    readLabel.textColor = LOGINTITLERGBA;
    readLabel.textAlignment = NSTextAlignmentRight;
    _readLabel = readLabel;
    [self addSubview:self.readLabel];
    UIButton *userAgreement = [UIButton buttonWithType:UIButtonTypeCustom];
    [userAgreement setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [userAgreement setTitle:@"《用户服务协议》" forState:UIControlStateNormal];
    [userAgreement setTitleColor:LOGINBUTTONBACKRGBA forState:UIControlStateNormal];
    [userAgreement.titleLabel setFont:[UIFont systemFontOfSize:fontSize]];
    _userAgreementBtn = userAgreement;
    [self addSubview:self.userAgreementBtn];
    UIButton *loginBySecretBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginBySecretBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [loginBySecretBtn setTitle:@"手机密码登录" forState:UIControlStateNormal];
    [loginBySecretBtn setTitleColor:LOGINBUTTONBACKRGBA forState:UIControlStateNormal];
    [loginBySecretBtn.titleLabel setFont:[UIFont systemFontOfSize:fontSize]];
    _loginBySecretBtn = loginBySecretBtn;
    [self addSubview:self.loginBySecretBtn];
    
    //布局
    WS(ws);
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(ws);
        make.height.mas_equalTo(250*SCALEUNIT);
    }];
    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.title.mas_bottom).with.offset(20*SCALEUNIT);
        make.centerX.mas_equalTo(ws);
        make.size.mas_equalTo(CGSizeMake(615*SCALEUNIT, 75*SCALEUNIT));
    }];
    [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.phoneView.mas_bottom).with.offset(30*SCALEUNIT);
        make.centerX.mas_equalTo(ws);
        make.size.mas_equalTo(CGSizeMake(615*SCALEUNIT, 75*SCALEUNIT));
    }];
    [self.codeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.centerY.mas_equalTo(ws.codeView);
        make.size.mas_equalTo(CGSizeMake(150*SCALEUNIT, 40*SCALEUNIT));
    }];
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.codeView.mas_bottom);
        make.left.mas_equalTo(ws.codeView);
        make.size.mas_equalTo(CGSizeMake(45*SCALEUNIT, 65*SCALEUNIT));
    }];
    [self.readLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(ws.selectBtn);
        make.left.mas_equalTo(ws.selectBtn.mas_right);
        make.width.mas_equalTo(150*SCALEUNIT);
    }];
    [self.userAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(ws.selectBtn);
        make.left.mas_equalTo(ws.readLabel.mas_right);
        make.size.mas_equalTo(220*SCALEUNIT);
    }];
    [self.loginBySecretBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.mas_equalTo(ws.userAgreementBtn);
        make.right.mas_equalTo(ws.codeView).with.offset(-10*SCALEUNIT);
        make.left.mas_equalTo(ws.userAgreementBtn.mas_right);
    }];
}

#pragma mark ==========改变协议选中状态==========
- (void)selectChange:(UIButton *)btn{
    btn.selected = !btn.selected;
    self.selectJudge = !self.selectJudge;
}





@end
